package com.unibuy.smartdevice.ui.recycler;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.unibuy.smartdevice.databinding.RecyclerDebugBinding;
import com.unibuy.smartdevice.databinding.RecyclerSettingListBinding;

import java.util.List;

public class RecyclerDebugAdpter extends RecyclerView.Adapter<RecyclerDebugAdpter.ViewHolder> {
    private final List<String> textList;

    public RecyclerDebugAdpter(List<String> textList) {
        this.textList = textList;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        RecyclerDebugBinding binding;

        public ViewHolder(@NonNull RecyclerDebugBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // 使用 ViewBinding 來綁定佈局
        RecyclerDebugBinding binding = RecyclerDebugBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String oneText = textList.get(position);
        holder.binding.textStatus.setText(oneText);
    }

    @Override
    public int getItemCount() {
        return textList.size();
    }

    public void addProductData(String text) {
        textList.add(text);
        notifyItemInserted(textList.size() -1);
    }
}
